﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ProgNetComponents.Design.TypeConverters
{
    public abstract class BaseConstTypeConverter : BaseListTypeConverter
    {
        protected abstract Type ConstantClass
        {
            get;
        }

        protected override System.Collections.ICollection GetStandardListValues()
        {
            PropertyInfo _Property = null;
            FieldInfo _Field = null;
            MethodInfo _Refresh = null;
            Type t = ConstantClass;
            if (t != null)
            {
                _Refresh = t.GetMethod("Refresh", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                if (_Refresh != null)
                {
                    _Refresh.Invoke(null, null);
                }
                _Property = t.GetSingleProperty("StaticCollection", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                if (_Property == null)
                    _Field = t.GetSingleField("StaticCollection", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);

                Dictionary<string, object> list = null;
                if (_Property != null)
                {
                    list = _Property.GetValue(null) as Dictionary<string, object>;
                }
                else if (_Field != null)
                {
                    list = _Field.GetValue(null) as Dictionary<string, object>;
                }
                if (list != null)
                    return list.Values;
            }
            return null;
        }
    }
}
